package com.taxshare.exception;

import cn.hutool.core.exceptions.ExceptionUtil;
import com.taxshare.response.beans.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;



/**
 * 统一异常处理类
 *
 */
@ControllerAdvice
@Slf4j
public class BaseExceptionController {

	/**
	 * 全局异常捕捉处理
	 *
	 * @param e
	 *            异常信息
	 * @return
	 */
	@ResponseBody
	@ExceptionHandler(value = Exception.class)
	public Response<String> errorHandler(Exception e) {
		// 打印日志
		log.error("统一异常捕获：", e);
		return Response.error(Response.ERROR, Response.ERROR_MSG, ExceptionUtil.getMessage(e));
	}

}
